<!--院系管理-->
<template>
    <div>
        <page-header title="班级信息管理" content="Class information" />
        <page-main>
            <h1>该功能正在开发中，敬请期待</h1>
        </page-main>
    </div>
</template>

<script>
import api from '../../api'
import {Message} from 'element-ui'

export default {
    name: 'class',
    data() {
        return {
            show: true, // 判断条件
            tableData: [{}],
            formData: {
                field102: 124,
                field101: 0
            },
            rules: {
                field102: [{
                    required: true,
                    message: '请选择院系',
                    trigger: 'change'
                }],
                field101: [{
                    required: true,
                    message: '请选择专业',
                    trigger: 'change'
                }]
            },
            field101Options: [],
            field102Options: []

        }
    },
    computed: {
        isEdit() {
            return this.$store.state.settings.mode // 需要监听的数据
        }
    },
    watch: {
        isEdit() {
            if (this.$store.state.settings.mode == 'mobile') {
                this.show = false
            } else {
                this.show = true
            }
        },
        'formData.field101': {
            // 对数据进行深度监听，如果数据发生变化，就获取培育计划表中的数据并渲染到表格上
            handler: function() {
                var _this = this
                this.tableData = []
                api.post('student/findStudentByMajorID', {
                    data: this.formData.field101})
                    .then(res => {
                        _this.tableData = res.data
                    })
            },
            deep: true
        }
    },
    created() {
        if (this.$store.state.settings.mode == 'mobile') {
            this.show = false
        } else {
            this.show = true
        }
        var _this = this
        api.post('department/findAll').then(res => {
            _this.field102Options = res.data
        })
        api.post('major/findByDepartmentID', {
            data: this.formData.field102})
            .then(res => {
                this.field101Options = res.data
                this.formData.field101 = res.data[0].id
            })
    },
    methods: {
        indexMethod(index) {
            return index + 1
        },
        // eslint-disable-next-line no-unused-vars
        clickTable(row, index, e) {
            console.log(row.course_name)
            this.$refs.refTable.toggleRowExpansion(row)
        },
        getRowKey(row) {
            return row.staffTypeId
        },
        findAll_Major() {
            this.tableData = []
            var _this = this
            api.post('major/findByDepartmentID', {
                data: this.formData.field102})
                .then(res => {
                    _this.field101Options = res.data
                    _this.formData.field101 = res.data[0].id
                })
        },
        handleDelete(row) {
            this.$confirm('此操作将永久删除该培育计划, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                api.post('student/deleteStudent', {
                    data: row})
                    .then(res => {
                        Message.error(res.msg)
                        location.reload()
                    })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                })
            })

        },
        change_Major() {
            this.tableData = []
            var _this = this
            api.post('student/findStudentByMajorID', {
                data: this.formData.field101})
                .then(res => {
                    _this.tableData = res.data
                })
        },
        add_cultivation_plan() {
            // 跳转路径
            this.$router.push({path: '/school/basic/add_class'})
        },
        goBack() {
            this.$router.push('/school/basic/student_information')
        }
    }
}
</script>
